package com.mall.search.controller;

import com.mall.common.dto.SkuEsModel;
import com.mall.common.exception.HttpStatusCode;
import com.mall.common.utils.Result;
import com.mall.search.service.ElasticsearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 谢君臣
 * @Date: 2022/7/31-9:06
 * @version: 1.0
 * @function:
 */
@RestController
@RequestMapping("/search/sku")
@Slf4j
public class ElasticsearchController {

    @Resource
    private ElasticsearchService elasticsearchService;

    @PostMapping("/test")
    public void test(){
        System.out.println("asdfasdf");
    }

    @PostMapping("/save")
    public Result productUp(@RequestBody List<SkuEsModel> skuEsModelList){
        log.info("获取请求数据");
        try {
            boolean res = elasticsearchService.productUp(skuEsModelList);
            if (res)
                return new Result().error(HttpStatusCode.PRODUCTUP_EXCEPTION.getCode(),HttpStatusCode.PRODUCTUP_EXCEPTION.getMsg());
            return new Result().ok(null);
        } catch (Exception e) {
            return new Result().error(HttpStatusCode.PRODUCTUP_EXCEPTION.getCode(),HttpStatusCode.PRODUCTUP_EXCEPTION.getMsg());
        }

    }
}
